import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
//1. 在路由配置文件中导入组件
import Review from '@/components/review'
import Detail from '@/components/detail'
import Answer from '@/components/answer'
import Service from '@/components/service'
// 配置双模块视图显示
import Detail2 from '@/components/detail2'
// 导入二级路由组件
import Pic from '@/components/detailpic'
import Video from '@/components/detailvideo'
Vue.use(Router)
    //设置push方法，避免路由重复切换时报异常
    //获取原型对象上的push函数
const originalPush = Router.prototype.push
    //修改原型对象中的push方法
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}



export default new Router({
    routes: [{
            // /代表项目根路径，默认路由
            path: '/',
            name: 'HelloWorld',
            // 命名视图
            components: {
                default: HelloWorld,
                // 指定router-view显示指定的组件    绑定在当前路径下的
                abc: Detail,
                xyz: Service
            }
        },
        //2. 配置路由
        {
            path: '/detail',
            name: 'Detail',
            component: Detail,
            children: [{
                    //  设置默认路由
                    path: '/',
                    name: 'Root',
                    component: Pic,
                }, {
                    //  二级及以后的路由的path不要加斜杠 /
                    path: 'pic',
                    name: 'Pic',
                    component: Pic,
                },
                {
                    path: 'video',
                    name: 'Video',
                    component: Video,
                },
            ]
        },
        //2. 配置路由
        {
            path: '/detail2',
            name: 'Detail2',
            component: Detail2,
            children: [{
                    //  设置默认路由
                    path: '/',
                    name: 'Root',
                    component: Pic,
                }, {
                    //  二级及以后的路由的path不要加斜杠 /
                    path: 'pic',
                    name: 'Pic',
                    component: Pic,
                },
                {
                    path: 'video',
                    name: 'Video',
                    component: Video,
                },
            ]
        },
        {
            // 携带商品id参数   查询对应评论
            path: '/review/:goodsid',
            name: 'Review',
            component: Review
        },
        {
            path: '/answer',
            name: 'Answer',
            component: Answer
        },
        {
            path: '/service',
            name: 'Service',
            component: Service
        }




    ],
    //3. 设置切换路由方式 默认是hash方式 就是带#的
    mode: 'history'
})